package com.hhs.storage.controller;

import com.hhs.storage.bean.JxcMenu;
import com.hhs.storage.bean.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("do/login")
public class LoginController {
    //登录后跳转到主页
    @RequestMapping("login")
    public String login(String account,String password){
        try {
            UsernamePasswordToken token = new UsernamePasswordToken(account, password);
            Subject subject = SecurityUtils.getSubject();
            subject.login(token);
            return "redirect:/go/index";
        }catch (Exception e){
            e.printStackTrace();
            return "redirect:/login";
        }
    }

    @RequestMapping("logout")
    public String logout(String account,String password){
            Subject subject = SecurityUtils.getSubject();
            subject.logout();
            return "redirect:/login";
    }
}
